from datetime import datetime
from project import db


class Message(db.Model):
    __tablename__='message'
    userId=db.Column(db.Integer,primary_key=True,comment="用户唯一标识")
    userName=db.Column(db.String(50),nullable=False,comment='用户名')
    gender=db.Column(db.String(50),nullable=False,default='先生',comment="性别")
    price=db.Column(db.String(50),nullable=False,comment="资费")
    relation=db.Column(db.String(50),nullable=False,default='00',comment='00:本人,01:父子,03:母子')
    phoneNumber=db.Column(db.String(60),nullable=False,default='手机号')
    broadband=db.Column(db.String(60),nullable=False,comment='宽带')
    total_price=db.Column(db.Integer,nullable=False,default=0.0,comment='合计')
    createTime=db.Column(db.DateTime,default=datetime.now(),comment='新增时间')
    statusTime=db.Column(db.DateTime,default=datetime.now(),comment="最后一次修改用户的时间")

class Orderinfo(db.Model):
    __tablename__ = 'orderinfo'
    id = db.Column(db.BIGINT, primary_key=True,autoincrement=True, comment='订单号')
    create_user = db.Column(db.String(50),nullable=False,default='营业员', comment='录入人')
    create_id = db.Column(db.Integer,nullable=False,default='10000', comment='录入人工号')
    package_id= db.Column(db.Integer, db.ForeignKey('price.id'), comment='套餐id')
    package_price = db.Column(db.Integer, nullable=False, comment='套餐总资费')
    user_price = db.Column(db.Integer, nullable=False, comment='用户总资费')
    userid = db.Column(db.BIGINT, db.ForeignKey('user.userid'),nullable=False,comment='用户id')
    customer_name = db.Column(db.String(50), nullable=False, comment='用户姓名')
    haoma=db.Column(db.String(50),nullable=False,comment='笔算号码')
    address = db.Column(db.String(1000),nullable=False,default='China', comment='地址')
    createTime = db.Column(db.DateTime, default=datetime.now(), comment='新增时间')
    price = db.relationship("Price", backref="orderinfo")
    userinfo = db.relationship("User", backref="orderinfo")


class Price(db.Model):
    __tablename__ = 'price'
    id = db.Column(db.Integer, primary_key=True, comment='套餐id')
    packagename=db.Column(db.String(50),nullable=False,comment="套餐名字")
    content_price = db.Column(db.Integer, nullable=False, comment='套餐价格')
    flow = db.Column(db.String(100), nullable=False, comment='流量')
    voice = db.Column(db.String(100), nullable=False, comment='语音')
    sms = db.Column(db.String(100), nullable=False, comment='短信')
    speed1 = db.Column(db.String(100), nullable=False, comment='网速1')
    speed2=db.Column(db.String(50),nullable=False,comment='网速2')
    cloud1=db.Column(db.String(100),nullable=False,comment='套餐附加1')
    cloud2 = db.Column(db.String(100), nullable=False, comment='套餐附加2')
    cloud3 = db.Column(db.String(100), nullable=False, comment='套餐附加3')
    cloud4 = db.Column(db.String(100), nullable=False, comment='套餐附加4')
    sub_card = db.Column(db.String(50), nullable=False, comment='副卡')


class Product(db.Model):
    __tablename__ = 'products'
    productid = db.Column(db.BIGINT, primary_key=True,nullable=False, comment='产品id')
    userid = db.Column(db.BIGINT, db.ForeignKey('user.userid'), nullable=False)
    phone_number = db.Column(db.String(100), nullable=False, comment='手机号')
    price = db.Column(db.Integer, nullable=False, comment='资费')
    broadband = db.Column(db.String(60), nullable=False, comment='宽带')
    total_price = db.Column(db.Integer, nullable=False, default=0.0, comment='合计')


class User(db.Model):
    __tablename__ = 'user'
    userid = db.Column(db.BIGINT, primary_key=True, nullable=False, comment='用户ID')
    username = db.Column(db.String(50), nullable=False, comment='姓名')
    gender = db.Column(db.String(50), nullable=False, default='先生', comment="性别")
    broadband = db.Column(db.String(60), nullable=False, comment='宽带')
    address = db.Column(db.String(150), nullable=False, default='China', comment='地址')
    promotioner=db.Column(db.String(50),nullable=False,default='营业员',comment='促销员')
    products = db.relationship('Product', backref='user', lazy=True)
